package mts.messages;

import mts.constants.MessageType;


public class FloorRequestMessage extends Message {

	public static final int INDEX_DESTINATION_FLOOR = Message.INDEX_MESSAGE_TYPE + 1;
	public static final int MESSAGE_LENGTH = INDEX_DESTINATION_FLOOR + 1;
	
	
	private byte destinationFloor;
	
	public byte getDestinationFloor() {
		return destinationFloor;
	}
	
	public FloorRequestMessage(byte destinationFloor) {
		this();
		this.destinationFloor = destinationFloor;
	}
	
	private FloorRequestMessage() {
		super(MessageType.FLOOR_REQUEST);
	}
	
	public static FloorRequestMessage deserialize(byte[] data) {
		FloorRequestMessage requestMessage = new FloorRequestMessage();
		
		requestMessage.destinationFloor = data[INDEX_DESTINATION_FLOOR];

		
		return requestMessage;
	}
	
	@Override
	public byte[] serialize() {
		byte[] data = new byte[MESSAGE_LENGTH];
		data[Message.INDEX_MESSAGE_TYPE] = getMessageType().getByteValue();	
		data[INDEX_DESTINATION_FLOOR] = destinationFloor;
		
		return data;
	}
	
	@Override
	public boolean equals(Object other) {
		if (!(other instanceof FloorRequestMessage)) {
			return false;
		}
		
		FloorRequestMessage o = (FloorRequestMessage)other;
		
		return destinationFloor == o.destinationFloor;
	}
	
	@Override
	public String toString() {
		return "FloorRequestMessage [" +
		"messageType: " + getMessageType() + 
		", destinationFloor: " + destinationFloor  +
		"]";
	}

}
